#ifndef _LONGGUI_COMMON_H
#define _LONGGUI_COMMON_H

#define LONGGUI_MAJOR_VERSION 1
#define LONGGUI_MINOR_VERSION 0
#define LONGGUI_MICRO_VERSION 0

/**
 * \def _VERSION_CODE(major, minor, micro)
 * \brief A macro that returns the version code from \a major, \a minor
 * and \a micro version number.
 *
 * LONGGUI uses this macro to evaluate the version code of current LONGGUI
 * library installed in your system, and define it to _LONGGUI_VERSION_CODE.
 *
 * \sa _LONGGUI_VERSION_CODE
 */
#define _VERSION_CODE(major, minor, micro)  (((major)<<16) | ((minor)<<8) | (micro))


/**
 * \def _LONGGUI_VERSION_CODE
 * \brief Version code of LONGGUI.
 *
 * \sa _VERSION_CODE
 */
#define _LONGGUI_VERSION_CODE \
        ((LONGGUI_MAJOR_VERSION << 16) | (LONGGUI_MINOR_VERSION << 8) | LONGGUI_MICRO_VERSION)

    /** @} end of version_info */

    /**
     * \defgroup basic_types Basic data types
     * @{
     */


/**
 * \var typedef unsigned char Uint8
 * \brief A type definition for an 8-bit unsigned character.
 */
typedef unsigned char   Uint8;
/**
 * \var typedef signed char Sint8
 * \brief A type definition for an 8-bit signed character.
 */
typedef signed char     Sint8;
/**
 * \var typedef unsigned short Uint16
 * \brief A type definition for a 16-bit unsigned integer.
 */
typedef unsigned short  Uint16;
/**
 * \var typedef signed short Sint16
 * \brief A type definition for a 16-bit signed integer.
 */
typedef signed short    Sint16;
/**
 * \var typedef unsigned int Uint32
 * \brief A type definition for a 32-bit unsigned integer.
 */
typedef unsigned int    Uint32;
/**
 * \var typedef signed int Sint32
 * \brief A type definition for a 32-bit signed integer.
 */
typedef signed int      Sint32;


#ifndef BOOL
typedef int BOOL;
#endif

/**
 * \def FALSE
 * \brief FALSE value, defined as 0 by LONGGUI.
 */
#ifndef FALSE
    #define FALSE       0
#endif
/**
 * \def TRUE
 * \brief TRUE value, defined as 1 by LONGGUI.
 */
#ifndef TRUE
    #define TRUE        1
#endif


/**
 * \def NULL
 * \brief A value indicates null pointer.
 */
#ifndef NULL
#define NULL            ((void *)0)
#endif

#define GUIAPI


/**
 * \var typedef unsigned int HWND
 * \brief Handle to main window or control.
 */
typedef unsigned int HWND;
/**

/**
 * \var typedef unsigned char BYTE
 * \brief A type definition for unsigned character (byte).
 */
#ifndef BYTE
typedef unsigned char   BYTE;
#endif
/**
 * \var typedef signed char SBYTE
 * \brief A type definition for signed character.
 */
typedef signed char     SBYTE;

/**
 * \var typedef unsigned short WORD
 * \brief A type definition for unsigned short integer (word).
 */
#ifndef WORD
typedef unsigned short  WORD;
#endif


/**
 * \var typedef signed short SWORD
 * \brief A type definition for signed short integer.
 */
typedef signed short    SWORD;

/**
 * \var typedef unsigned long DWORD
 * \brief A type definition for unsigned long integer (double word).
 */
#ifndef DWORD
typedef unsigned long   DWORD;
#endif

/**
 * \var typedef signed long SDWORD
 * \brief A type definition for signed long integer.
 */
typedef signed long     SDWORD;

/**
 * \var typedef unsigned int UINT
 * \brief A type definition for unsigned integer.
 */
#ifndef UINT
typedef unsigned int    UINT;
#endif

/**
 * \var typedef long LONG
 * \brief A type definition for long integer.
 */
#ifndef LONG
typedef long            LONG;
#endif

/**
 * \var typedef unsigned int WPARAM
 * \brief A type definition for the first message paramter.
 */
typedef unsigned int    WPARAM;

/**
 * \var typedef unsigned long LPARAM
 * \brief A type definition for the second message paramter.
 */
typedef unsigned long   LPARAM;

/**
 * \def LOBYTE(w)
 * \brief Returns the low byte of the word \a w.
 *
 * \sa MAKEWORD
 */
#define LOBYTE(w)           ((BYTE)(w))
/**
 * \def HIBYTE(w)
 * \brief Returns the high byte of the word \a w.
 *
 * \sa MAKEWORD
 */
#define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))
/**
 * \def MAKEWORD(low, high)
 * \brief Makes a word from \a low byte and \a high byte.
 */
#define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))

/**
 * \def LOWORD(l)
 * \brief Returns the low word of the double word \a l
 *
 * \sa MAKELONG
 */
#define LOWORD(l)           ((WORD)(DWORD)(l))
/**
 * \def HIWORD(l)
 * \brief Returns the high word of the double word \a l
 *
 * \sa MAKELONG
 */
#define HIWORD(l)           ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
/**
 * \def LOSWORD(l)
 * \brief Returns the low signed word of the double word \a l
 *
 * \sa MAKELONG
 */
#define LOSWORD(l)          ((SWORD)(DWORD)(l))
/**
 * \def HISWORD(l)
 * \brief Returns the high signed word of the double word \a l
 *
 * \sa MAKELONG
 */
#define HISWORD(l)          ((SWORD)((((DWORD)(l)) >> 16) & 0xFFFF))

/**
 * \def MAKELONG(low, high)
 * \brief Makes a double word from \a low word and \a high word.
 */
#define MAKELONG(low, high) ((DWORD)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))

/**
 * A rectangle defined by coordinates of corners.
 *
 * \note The lower-right corner does not belong to the rectangle,
 * i.e. the bottom horizontal line and the right vertical line are excluded
 * from the retangle.
 *
 * \sa PRECT, GAL_Rect
 */
typedef struct _RECT
{
    /**
     * The x coordinate of the upper-left corner of the rectangle.
     */
    short left;
    /**
     * The y coordinate of the upper-left corner of the rectangle.
     */
    short top;
    /**
     * The x coordinate of the lower-right corner of the rectangle.
     */
    short right;
    /**
     * The y coordinate of the lower-right corner of the rectangle.
     */
    short bottom;
} RECT;
/**
 * \var typedef RECT* PRECT
 * \brief Data type of the pointer to a RECT.
 *
 * \sa RECT
 */
typedef RECT* PRECT;

/**
 * Point structure.
 * \sa PPOINT
 */
typedef struct _POINT
{
    /**
     * The x coordinate of the point.
     */
    int x;
    /**
     * The y coordinate of the point.
     */
    int y;
} POINT;
/**
 * \var typedef POINT* PPOINT
 * \brief Data type of the pointer to a POINT.
 *
 * \sa POINT
 */
typedef POINT* PPOINT;

/**
 * \defgroup err_codes Error codes
 * @{
 */
/**
* \def ERR_OK
* \brief Return value error ok.
*/
#define ERR_OK                   0
/**
 * \def ERR_INV_HWND
 * \brief Return value invalid window handle error.
 */
#define ERR_INV_HWND            -1

/**
 * \def ERR_QUEUE_FULL
 * \brief Return value queue is full error.
 */
#define ERR_QUEUE_FULL          -2

/**
 * \def ERR_INVALID_HANDLE
 * \brief Return value invalid handle error.
 */
#define ERR_INVALID_HANDLE      -3

/**
 * \def ERR_INVALID_HMENU
 * \brief Return value invalid menu handle error.
 */
#define ERR_INVALID_HMENU       -4
/**
 * \def ERR_INVALID_POS
 * \brief Return value invalid postion error.
 */
#define ERR_INVALID_POS         -5

/**
* \def ERR_INVALID_ID
* \brief Return value invalid id error.
*/
#define ERR_INVALID_ID          -6

/**
* \def ERR_RES_ALLOCATION
* \brief Return value allocation resource error .
*/
#define ERR_RES_ALLOCATION      -7

/**
* \def ERR_CTRLCLASS_INVNAME
* \brief Return value invalid name of control class error.
*/
#define ERR_CTRLCLASS_INVNAME   -8

/**
* \def ERR_CTRLCLASS_INVLEN
* \brief Return value control class invalid length.
*/
#define ERR_CTRLCLASS_INVLEN    -9

/**
* \def ERR_CTRLCLASS_MEM
* \brief Return value control class memory error.
*/
#define ERR_CTRLCLASS_MEM       -10

/**
* \def ERR_CTRLCLASS_INUSE
* \brief Return value inuse control class error.
*/
#define ERR_CTRLCLASS_INUSE     -11

/**
* \def ERR_ALREADY_EXIST
* \brief Return value already exit error.
*/
#define ERR_ALREADY_EXIST       -12

/**
* \def ERR_NO_MATCH
* \brief Return no match error.
*/
#define ERR_NO_MATCH            -13

/**
* \def ERR_BAD_OWNER
* \brief Return BAD owner error.
*/
#define ERR_BAD_OWNER           -14

/**
* \def ERR_IME_TOOMUCHIMEWND
* \brief Return value toom much IME window error.
*/
#define ERR_IME_TOOMUCHIMEWND   -15

/**
* \def ERR_IME_NOSUCHIMEWND
* \brief Return value no such IME wondow error.
*/
#define ERR_IME_NOSUCHIMEWND    -16

/**
* \def ERR_IME_NOIMEWND
* \brief Return value no IME wondow error.
*/
#define ERR_IME_NOIMEWND        -17

/**
* \def ERR_CONFIG_FILE
* \brief Return value configure file error.
*/
#define ERR_CONFIG_FILE         -18

/**
* \def ERR_FILE_IO
* \brief Return value file io error.
*/
#define ERR_FILE_IO             -19

/**
* \def ERR_GFX_ENGINE
* \brief Return value GFX engine error.
*/
#define ERR_GFX_ENGINE          -20

/**
* \def ERR_INPUT_ENGINE
* \brief Return value input engine error.
*/
#define ERR_INPUT_ENGINE        -21

/**
* \def ERR_NO_ENGINE
* \brief Return value no engine error.
*/
#define ERR_NO_ENGINE           -22

/**
* \def ERR_INVALID_ARGS
* \brief Return value invalid args.
*/
#define ERR_INVALID_ARGS        -23

   /** @} end of err_codes */

   /**
    * \defgroup misc_macros Miscellaneous macros
    * @{
    */
/**
* \def TABLESIZE(table)
* \brief A macro returns the number of elements in a \a table.
*/
#define TABLESIZE(table)    (sizeof(table)/sizeof(table[0]))

/* MAX/MIN/ABS macors */
/**
* \def MAX(x, y)
* \brief A macro returns the maximum of \a x and \a y.
*/
#ifndef MAX
#define MAX(x, y)           (((x) > (y))?(x):(y))
#endif
/**
* \def MIN(x, y)
* \brief A macro returns the minimum of \a x and \a y.
*/
#ifndef MIN
//#define MIN(x, y)           (((x) < (y))?(x):(y))
#endif
/**
* \def ABS(x)
* \brief A macro returns the absolute value of \a x.
*/
#ifndef ABS
#define ABS(x)              (((x)<0) ? -(x) : (x))
#endif


#define SCANCODE_ESCAPE                 1

#define SCANCODE_1                      2
#define SCANCODE_2                      3
#define SCANCODE_3                      4
#define SCANCODE_4                      5
#define SCANCODE_5                      6
#define SCANCODE_6                      7
#define SCANCODE_7                      8
#define SCANCODE_8                      9
#define SCANCODE_9                      10
#define SCANCODE_0                      11

#define SCANCODE_MINUS                  12
#define SCANCODE_EQUAL                  13

#define SCANCODE_BACKSPACE              14
#define SCANCODE_TAB                    15

#define SCANCODE_Q                      16
#define SCANCODE_W                      17
#define SCANCODE_E                      18
#define SCANCODE_R                      19
#define SCANCODE_T                      20
#define SCANCODE_Y                      21
#define SCANCODE_U                      22
#define SCANCODE_I                      23
#define SCANCODE_O                      24
#define SCANCODE_P                      25
#define SCANCODE_BRACKET_LEFT           26
#define SCANCODE_BRACKET_RIGHT          27

#define SCANCODE_ENTER                  28

#define SCANCODE_LEFTCONTROL            29

#define SCANCODE_A                      30
#define SCANCODE_S                      31
#define SCANCODE_D                      32
#define SCANCODE_F                      33
#define SCANCODE_G                      34
#define SCANCODE_H                      35
#define SCANCODE_J                      36
#define SCANCODE_K                      37
#define SCANCODE_L                      38
#define SCANCODE_SEMICOLON              39
#define SCANCODE_APOSTROPHE             40
#define SCANCODE_GRAVE                  41

#define SCANCODE_LEFTSHIFT              42
#define SCANCODE_BACKSLASH              43

#define SCANCODE_Z                      44
#define SCANCODE_X                      45
#define SCANCODE_C                      46
#define SCANCODE_V                      47
#define SCANCODE_B                      48
#define SCANCODE_N                      49
#define SCANCODE_M                      50
#define SCANCODE_COMMA                  51
#define SCANCODE_PERIOD                 52
#define SCANCODE_SLASH                  53

#define SCANCODE_RIGHTSHIFT             54
#define SCANCODE_KEYPADMULTIPLY         55

#define SCANCODE_LEFTALT                56
#define SCANCODE_SPACE                  57
#define SCANCODE_CAPSLOCK               58

#define SCANCODE_F1                     59
#define SCANCODE_F2                     60
#define SCANCODE_F3                     61
#define SCANCODE_F4                     62
#define SCANCODE_F5                     63
#define SCANCODE_F6                     64
#define SCANCODE_F7                     65
#define SCANCODE_F8                     66
#define SCANCODE_F9                     67
#define SCANCODE_F10                    68

#define SCANCODE_NUMLOCK                69
#define SCANCODE_SCROLLLOCK             70

#define SCANCODE_KEYPAD7                71
#define SCANCODE_CURSORUPLEFT           71
#define SCANCODE_KEYPAD8                72
#define SCANCODE_CURSORUP               72
#define SCANCODE_KEYPAD9                73
#define SCANCODE_CURSORUPRIGHT          73
#define SCANCODE_KEYPADMINUS            74
#define SCANCODE_KEYPAD4                75
#define SCANCODE_CURSORLEFT             75
#define SCANCODE_KEYPAD5                76
#define SCANCODE_KEYPAD6                77
#define SCANCODE_CURSORRIGHT            77
#define SCANCODE_KEYPADPLUS             78
#define SCANCODE_KEYPAD1                79
#define SCANCODE_CURSORDOWNLEFT         79
#define SCANCODE_KEYPAD2                80
#define SCANCODE_CURSORDOWN             80
#define SCANCODE_KEYPAD3                81
#define SCANCODE_CURSORDOWNRIGHT        81
#define SCANCODE_KEYPAD0                82
#define SCANCODE_KEYPADPERIOD           83

#define SCANCODE_LESS                   86

#define SCANCODE_F11                    87
#define SCANCODE_F12                    88

#define SCANCODE_KEYPADENTER            96
#define SCANCODE_RIGHTCONTROL           97
#define SCANCODE_CONTROL                97
#define SCANCODE_KEYPADDIVIDE           98
#define SCANCODE_PRINTSCREEN            99
#define SCANCODE_RIGHTALT               100
#define SCANCODE_BREAK                  101    /* Beware: is 119     */
#define SCANCODE_BREAK_ALTERNATIVE      119    /* on some keyboards! */

#define SCANCODE_HOME                   102
#define SCANCODE_CURSORBLOCKUP          103    /* Cursor key block */
#define SCANCODE_PAGEUP                 104
#define SCANCODE_CURSORBLOCKLEFT        105    /* Cursor key block */
#define SCANCODE_CURSORBLOCKRIGHT       106    /* Cursor key block */
#define SCANCODE_END                    107
#define SCANCODE_CURSORBLOCKDOWN        108    /* Cursor key block */
#define SCANCODE_PAGEDOWN               109
#define SCANCODE_INSERT                 110
#define SCANCODE_REMOVE                 111

#define SCANCODE_PAUSE                  119

#define SCANCODE_POWER                  120
#define SCANCODE_SLEEP                  121
#define SCANCODE_WAKEUP                 122

#define SCANCODE_LEFTWIN                125
#define SCANCODE_RIGHTWIN               126
#define SCANCODE_MENU                   127

#define SCANCODE_LEFTBUTTON             0x1000
#define SCANCODE_RIGHTBUTTON            0x2000
#define SCANCODE_MIDDLBUTTON            0x4000


#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
};  /* end of extern "C" */
#endif

#endif
